package com.hongkl.controller;

import com.hongkl.entity.User;
import com.hongkl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public void login(String username,String password){

        System.out.println(username);
        System.out.println(password);


        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        userService.getUser(user);
    }


    @RequestMapping("/all")
    public void getUserInfoAll(){
        List<User> users = userService.getAll();
        users.forEach(item -> {
            System.out.println(item.getUsername());
        });
    }


    @RequestMapping("/get")
    public User getUserInfo(String username){

        User userInfo = userService.getUserInfo(username);
        return userInfo;

    }

    @RequestMapping("/update")
    @ResponseBody
    public Integer updateUserInfo(User user){

        return userService.updateUserInfo(user);

    }

    @RequestMapping("/delete")
    @ResponseBody
    public Integer updateUserInfo(int id){
        return userService.deleteUserInfo(id);
    }





}
